﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameLib;
using Sandbox.ContentTypes;
using Sandbox.Names;
using System.Windows.Controls;
using Sandbox.Scene.Components;

namespace Sandbox.Scene
{
	public class EntitySceneObject
	{
		public EntitySceneObject(MapScene scene, Entity entity)
		{
			m_Scene = scene;
			m_Entity = entity;

			AttachComponent(m_SpriteComponent);

			m_SpriteComponent.Sprite = m_Entity.Type.Content.Get<Sprite>(ContentNames.EntitySprite);

		}

		public void Display()
		{
			foreach (var component in m_Components)
			{
				component.Display();
			}
		}

		public void AttachComponent(SceneObjectComponent component)
		{
			if (!m_Components.Contains(component))
			{
				component.Detach();
				m_Components.Add(component);
				component.OnAttachedTo(this);
			}
		}

		public void DetachComponent(SceneObjectComponent component)
		{
			if (m_Components.Remove(component))
			{
				component.OnDetached();
			}
		}

		private MapScene m_Scene = null;
		private Entity m_Entity = null;
		private SpriteComponent m_SpriteComponent = new SpriteComponent();

		private List<SceneObjectComponent> m_Components = new List<SceneObjectComponent>();
	}
}
